﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.ApplicationBlocks.Data;
using TransportManager.UI.Pages;
namespace TransportManager.Web.Admin
{
    /// <summary>
    /// function 的摘要说明。
    /// </summary>
    public class function2 : BasePage
    {
        protected System.Data.DataTable dt;
        protected String Sqlstr;
        protected System.Web.UI.WebControls.DataGrid dg;
        protected System.Web.UI.WebControls.Button Button1;

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (Session.Count < 2)
            {
                Response.Write("请登陆");
                Response.End();
            }
            if (Page.IsPostBack) return;
            Bingding();

        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.dg.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dg_DeleteCommand);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
        private void Bingding()
        {
            Sqlstr = "declare @funcation varchar(500);select @funcation=functioncode from purview_Role where code = '" + Request.QueryString[0] + "';";
            Sqlstr += "select id, name,path,fathername,codesoncorp from purview_function where  CHARINDEX('|'+ltrim(str(id))+'|',@funcation)>0 ";
            dt = SqlHelper.ExecuteDataset(Session["Conn"].ToString(), CommandType.Text, Sqlstr).Tables[0];
            dg.DataSource = dt.DefaultView;
            dg.DataBind();
        }

        private void dg_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            Sqlstr = "update purview_Role  set functioncode= REPLACE(functioncode,'|" + dg.DataKeys[e.Item.ItemIndex].ToString() + "|','') where code ='" + Request.QueryString[0] + "'";
            //Response.Write(Sqlstr);
            //Response.End();
            SqlHelper.ExecuteNonQuery(Session["Conn"].ToString(), CommandType.Text, Sqlstr);
            Bingding();
        }

        private void Button1_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("purview_Role.aspx");
        }
        public String corpString(object code)
        {
            Sqlstr = "select name from CodeCorpType where code='" + code.ToString() + "'";
            dt = SqlHelper.ExecuteDataset(Session["Conn"].ToString(), CommandType.Text, Sqlstr).Tables[0];
            return dt.Rows[0][0].ToString();

        }

    }
}
